/*
 * @Description: 对象流
 * @Author: rendc
 * @Date: 2025-08-22 10:29:53
 * @LastEditors: rendc
 * @LastEditTime: 2025-08-22 11:31:59
 */

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TestObject {

  public static void main(String[] args) throws Exception {
    // // 创建学生对象
    // Student s = new Student("张三", 18);
    // // 创建对象输出流
    // ObjectOutputStream oos = new ObjectOutputStream(
    // new FileOutputStream("studentyouxiliehua.txt"));
    // // 写到文件中
    // oos.writeObject(s);
    // // 关闭资源 只关增强流
    // oos.close();
    // 读取文件中内容
    ObjectInputStream ois = new ObjectInputStream(
        new FileInputStream("studentyouxiliehua.txt"));
    // 转换为学生对象
    Student s = (Student) ois.readObject();
    // Student s2 = (Student) ois.readObject();
    System.out.println("s:" + s);
    // System.out.println("s2:" + s2);
    // 实际开发中写多个对象一般会写到集合中
    // 关闭资源
    ois.close();

  }
}